package com.wuliu.system.service.delayqueue.impl;

import cn.hutool.core.map.MapUtil;
import com.wuliu.common.constant.OrderConstants;
import com.wuliu.system.domain.TspOrderPre;
import com.wuliu.system.mapper.TspOrderPreMapper;
import com.wuliu.system.service.ISysPushMsgService;
import com.wuliu.system.service.delayqueue.RedisDelayQueueHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 预约单超时未揽收处理类
 *
 * @author realue
 * @version 1.0
 * @date 2023-11-17 17:24
 */
@Component
@Slf4j
public class OrderCollectTimeout implements RedisDelayQueueHandle<Map<String, Object>> {
    @Resource
    private TspOrderPreMapper tspOrderPreMapper;
    @Resource
    private ISysPushMsgService sysPushMsgService;

    @Override
    public void execute(Map<String, Object> map) {
        log.info("消费预约单超时未揽收处理消息:{}", map);
        //TODO 订单超时未揽收处理
        String orderId = MapUtil.getStr(map, "orderId");
        TspOrderPre tspOrderPre = tspOrderPreMapper.selectTspOrderPreById(orderId);
        if (null != tspOrderPre && tspOrderPre.getStatus() == OrderConstants.ORDER_PRE_STATUS_1) {
            sysPushMsgService.createPushMsg(2, tspOrderPre.getGrabUserTel(), tspOrderPre.getSysAccount());
        } else {
            log.error("预约单[{}]不存在或已揽收,", orderId);
        }
    }
}
